namespace ApplicationControllerExample.Model
{
    using Core;
    using EventAggregator;
    using StructureMap;

    public class ApplicationController : IApplicationController
    {
        public ApplicationController(IContainer container, IEventPublisher eventPublisher)
        {
            Container = container;
            EventPublisher = eventPublisher;

            Container.Inject<IApplicationController>(this);
        }

        private IContainer Container { get; set; }
        private IEventPublisher EventPublisher { get; set; }

        #region IApplicationController Members

        public void Execute<T>(T commandData)
        {
            var command = Container.TryGetInstance<ICommand<T>>();
            if (command != null)
                command.Execute(commandData);
        }

        public void Raise<T>(T eventData)
        {
            EventPublisher.Publish(eventData);
        }

        #endregion
    }
}